// index.js
// 获取应用实例
let scrollTop = 0;
let screenHeight = 0;
let moveResult = {}
let start = 0

Page({
  data: {
    images: [{
      id: 1,
      url: 'https://img-blog.csdnimg.cn/20201223163901610.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1dhbGxfRTEwNTc3MzY2MDU=,size_16,color_FFFFFF,t_70#pic_center',
    }, {
      id: 2,
      url: 'https://images2015.cnblogs.com/blog/784641/201606/784641-20160612211349449-166097915.jpg'
    }, {
      id: 3,
      url: 'https://profile.csdnimg.cn/8/1/4/1_wall_e1057736605'
    }, {
      id: 4,
      url: 'https://images2015.cnblogs.com/blog/784641/201606/784641-20160612210641574-222267045.jpg'
    }],
    delvisa: false,
  },
  onLoad() {
    const system = wx.getSystemInfoSync()
    screenHeight = system.windowHeight
  },
  onPageScroll(e) {
    scrollTop = e.scrollTop
  },
  show(e) {
    const imageIdx = e.currentTarget.dataset.idx
    const images = this.data.images
    const urls = images.map(x => x.url)
    wx.previewImage({
      current: images[imageIdx].url,
      urls: urls
    })
  },
  changemove(e) {
    console.log(e)
    const idx = e.currentTarget.dataset.idx
    if (start === 0) {
      return
    }
    this.setData({
      delvisa: true
    })
    // 图片距离顶部的距离
    const imgTop = e.currentTarget.offsetTop - scrollTop
    const imgmovedel = screenHeight - imgTop - 100
    const del = imgmovedel - e.detail.y
    moveResult = {
      del,
      imageIdx: idx,
      // x: e.currentTarget.x,
      // y: e.currentTarget.y,
    }
    console.log(moveResult)
  },
  start(e) {
    start = 1
  },
  end(e) {
    start = 0
    const images = this.data.images
    if (moveResult.del < 10) {
      images.splice(moveResult.imageIdx, 1)
    // } else {
    //   if (moveResult.x) {
    //     images[moveResult.imageIdx].x = moveResult.x
    //     images[moveResult.imageIdx].y = moveResult.y
    //   }
    }
    this.setData({
      images,
      delvisa: false
    })
  }
})
